package com.hdd.biz.operate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdd.biz.operate.dto.FeedbackInfoRequest;
import com.hdd.biz.operate.dto.FeedbackListRequest;
import com.hdd.biz.operate.dto.FeedbackRequest;
import com.hdd.biz.operate.entity.Feedback;
import com.hdd.biz.operate.mapper.FeedbackMapper;
import com.hdd.biz.operate.service.FeedbackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.biz.painting.entity.MaterialKind;
import com.hdd.dto.SuperResponse;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 反馈建议记录表 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-03-09
 */
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {


    @Override
    public SuperResponse list(FeedbackListRequest request) {
        SuperResponse response = new SuperResponse();
        QueryWrapper<Feedback> wrapper = new QueryWrapper();
        Page<Feedback> pages = new Page<>(request.getPageNo(),request.getPageSize());
        IPage<Feedback> mapIPage = baseMapper.selectPage(pages, wrapper);
        List<Feedback> agents = mapIPage.getRecords();
        response.setItems(agents);
        response.setTotals(pages.getTotal());
        return response;
    }

    @Override
    public SuperResponse info(FeedbackRequest request) {
        SuperResponse response = new SuperResponse();
        response.setItem(baseMapper.selectById(request.getId()));
        return response;
    }

    @Override
    public SuperResponse udpate(FeedbackInfoRequest request) {
        SuperResponse response = new SuperResponse();
        Feedback feedback = new Feedback();
        feedback.setId(request.getId());
        feedback.setStatus(request.getStatus());
        feedback.setRemarks(request.getRemarks());
        feedback.setDescription(request.getDescription());
        baseMapper.updateById(feedback);
        return response;
    }

    @Override
    public SuperResponse delete(FeedbackRequest request) {
        SuperResponse response = new SuperResponse();
        Feedback feedback = new Feedback();
        feedback.setId(request.getId());
        feedback.setDelFlag(1);
        baseMapper.updateById(feedback);
        return response;
    }
}
